#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H

#include <QDialog>
#include <QSerialPort>

QT_BEGIN_NAMESPACE

namespace Ui {
class SettingsDialog;
}

class QIntValidator;

QT_END_NAMESPACE

class SettingsDialog : public QDialog
{
    Q_OBJECT

public:
    struct Settings
    {
        QString name;
        qint32 baudRate;
        QString strBaudRate;
        QSerialPort::DataBits dataBits;
        QString strDataBits;
        QSerialPort::Parity parity;
        QString strParity;
        QSerialPort::StopBits stopBits;
        QString strStopBits;
        QSerialPort::FlowControl flowControl;
        QString strFlowControl;
    };

public:
    explicit SettingsDialog(QWidget *parent = nullptr);
    ~SettingsDialog();

    Settings settings() const;

signals:
    void applied();

public slots:
    void apply();
    void cancel();

private slots:
    void checkCustomBaudRatePolicy(int idx);
    void updatePortNames();

private:
    void fillPortsParameters();
    void updateSettings();

private:
    Ui::SettingsDialog *ui = nullptr;
    Settings m_currentSettings;
    QIntValidator *m_intValidator = nullptr;
    QList<QString> portNames;
};

#endif // SETTINGSDIALOG_H
